/*
 * Copyright 2010-2011 ESunny.com All right reserved. This software is the confidential and proprietary information of
 * ESunny.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into with ESunny.com.
 */
package com.xjt.common;

import java.util.Date;

import com.xjt.common.Types.USER_AUTHORITY;
import com.xjt.query.dao.pojo.QueryUser;

/**
 * VM 中使用的公共方法类
 * 
 * @author Jet Xu 2012-8-3 上午10:23:17
 */
public class VmCommonUtils {

    public static boolean isPayUser(QueryUser userInfo) {
        return (getUserType(userInfo) == 9);
    }

    /**
     * 获取用户类型
     * 
     * @param userInfo 用户信息
     * @return 0：用户不存在 1：免费用户 2：付费用户，已到期。9：付费用户，正在使用
     */
    public static int getUserType(QueryUser userInfo) {
        int result = 1;
        if (null != userInfo && null != userInfo.getUserAuthority()) {
            if (USER_AUTHORITY.PAY == userInfo.getUserAuthority().intValue()) {
                result = 2;
                Date endDate = userInfo.getEffectiveEndDate();
                if (null != endDate) {
                    // 获取下一天和当前时间对比
                    endDate = DateUtils.getFutureDayInDays(endDate, 1);
                    if (endDate.after(new Date())) {
                        result = 9;
                    }
                }
            } else {
                result = 1;
            }
        }
        return result;
    }
}
